package cn.yunhe.dao.impl;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import cn.yunhe.dao.Bookdao;
import cn.yunhe.dao.Studentdao;
import cn.yunhe.dao.Userdao;
import cn.yunhe.entity.Book;
import cn.yunhe.entity.Student;
import cn.yunhe.entity.User;

public class StudentDaoImpl {
	String resource="Config.xml";
	InputStream inputstream;
	SqlSessionFactory ssf;
	public List<Student> findAll() throws IOException  {
		inputstream=Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		Studentdao studentdao=sqlsession.getMapper(Studentdao.class);
		List<Student> studentlist=studentdao.findAllStudent();
		sqlsession.close();
		return studentlist;
	}

	public Student Findstudentbyid(String id) throws IOException{
		inputstream = Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		Studentdao studentdao=sqlsession.getMapper(Studentdao.class);
		Student student=studentdao.findStudentBySid(id);
		sqlsession.close();
		return student;
		
	}
	
}
